package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.view.rebound.ReboundListView;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.adapter.TwoListAdapter;
import com.zcx.qshop.conn.JsonTypelistAsyGet;
import com.zcx.qshop.view.TitleView;

/**
 * Created by Administrator on 2015/8/17 0017.
 */
public class TwoListActivity extends QSActivity {

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.two_list_list_view) private ReboundListView reboundListView;

    private TwoListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_two_list);

        JsonTypelistAsyGet.TypeOne typeOne = (JsonTypelistAsyGet.TypeOne) getIntent().getSerializableExtra("TypeOne");

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName(typeOne.typetitle);

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        new JsonTypelistAsyGet(QSApplication.QSPreferences.readCity().code, typeOne.typeid, new AsyCallBack<JsonTypelistAsyGet.Info>(){

            @Override
            public void onSuccess(String toast, int type, JsonTypelistAsyGet.Info info) throws Exception {

                reboundListView.setAdapter(adapter = new TwoListAdapter(TwoListActivity.this, reboundListView, info.typeOnes));

            }

        }).execute(this);

        reboundListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                startVerifyActivity(ThreeListActivity.class, getIntent().putExtra("TypeTwo", adapter.getItem(position)));

            }

        });

    }

}
